import { filterTree, sortAsyncRoutes } from '@/router/utils'
import { flattenTree } from '@/router/utils'
import { defineStore } from 'pinia'
import { ref } from 'vue'

import { constantMenus } from '@/router'
export const usePermissionStore = defineStore('permission', () => {
  const wholeMenus = ref<any[]>([]) // 整体路由生成的菜单（静态、动态）
  const flatteningRoutes = ref<any>([]) // 整体路由（一维数组格式）

  const handleWholeMenus = (routes: any[]) => {
    wholeMenus.value = filterTree(sortAsyncRoutes(constantMenus.concat(routes)))

    flatteningRoutes.value = flattenTree(routes)
  }
  return { wholeMenus, flatteningRoutes, handleWholeMenus }
})
